package com.siwei.mes.entity.system;

import cn.dev33.satoken.stp.StpUtil;
import com.siwei.mes.common.validator.AddGroup;
import com.siwei.mes.common.validator.UpdateGroup;
import com.siwei.mes.config.UidUtils;
import com.siwei.mes.enums.GenerateCodeEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;

import javax.persistence.Column;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;


/**
 * 供应商物料表(SupplierCompanyMaterials)实体类
 *
 * @author linzi
 * @since 2024-07-17 23:04:40
 */
@Data
@Accessors(chain = true)
@Table(name = "pk_supplier_company_materials")
@ApiModel(value = "SupplierCompanyMaterials", description = "供应商物料表")
public class SupplierCompanyMaterials implements Serializable {
    private static final long serialVersionUID = 385642531302263569L;
    /**
     * 主键id
     */
    @Id
    @ApiModelProperty(value = "供应商物料表主键ID", name = "id")
    @NotNull(groups = {UpdateGroup.class}, message = "供应商物料主键id为空")
    private Long id;
    /**
     * 供应商id
     */
    @Column(name = "supplier_company_id")
    @ApiModelProperty(value = "供应商id", name = "supplierCompanyId")
    private Long supplierCompanyId;
    /**
     * 物料编号
     */
    @Column(name = "materials_no")
    @ApiModelProperty(value = "物料编号", name = "materialsNo")
    private String materialsNo;
    /**
     * 物料类型  字典 MATERIAL_TYPE  1-水泥 2-粉煤灰 3-矿渣粉 4-粗骨料 5-细骨料 6-外加剂 7-混凝土
     */
    @Column(name = "materials_type")
    @ApiModelProperty(value = "物料类型  字典 MATERIAL_TYPE", name = "materialsType")
    //@NotNull(groups = {AddGroup.class, UpdateGroup.class}, message = "物料类型为空")
    private Integer materialsType;

    /**
     * 物料id  对应pk_materials的id
     */
    @Column(name = "materials_id")
    @ApiModelProperty(value = "物料id  对应pk_materials的id")
    private Long materialsId;

    /**
     * 物料及规格配置id  pk_materials_spec_config的id
     */
    @Column(name = "spec_id")
    @ApiModelProperty(value = "物料及规格配置id  pk_materials_spec_config的id", name = "specId")
    @NotNull(groups = {AddGroup.class, UpdateGroup.class}, message = "请先配置物料规则")
    private Long specId;
    /**
     * 厂家
     */
    @Column(name = "manufacturers")
    @ApiModelProperty(value = "厂家", name = "manufacturers")
    @NotBlank(groups = {AddGroup.class, UpdateGroup.class}, message = "厂家为空")
    private String manufacturers;

    /**
     * 厂家简称
     */
    @Column(name = "manufacturers_called")
    @ApiModelProperty(value = "厂家简称", name = "manufacturersCalled")
    private String manufacturersCalled;

    @Column(name = "unit_price")
    @ApiModelProperty(value = "单价")
    private BigDecimal unitPrice;
    /**
     * 形式检验编号
     */
    @Column(name = "inspection_no")
    @ApiModelProperty(value = "形式检验编号", name = "inspectionNo")
    private String inspectionNo;
    /**
     * 形式检验结果
     */
    @Column(name = "inspection_result")
    @ApiModelProperty(value = "形式检验结果", name = "inspectionResult")
    private String inspectionResult;
    /**
     * 形式检验开始时间
     */
    @Column(name = "inspection_date_start")
    @ApiModelProperty(value = "形式检验开始时间", name = "inspectionDateStart")
    private Date inspectionDateStart;
    /**
     * 形式检验结束时间
     */
    @Column(name = "inspection_date_end")
    @ApiModelProperty(value = "形式检验结束时间", name = "inspectionDateEnd")
    private Date inspectionDateEnd;
    /**
     * 甲供 1-是 0-否
     */
    @Column(name = "self_supply")
    @ApiModelProperty(value = "甲供 1-是 0-否", name = "selfSupply")
    private String selfSupply;
    /**
     * 最后一次委托编号
     */
    @Column(name = "last_experiment_no")
    @ApiModelProperty(value = "最后一次委托编号", name = "lastExperimentNo")
    private String lastExperimentNo;
    /**
     * 最后一次委托id
     */
    @Column(name = "last_experiment_id")
    @ApiModelProperty(value = "最后一次委托id", name = "lastExperimentId")
    private Long lastExperimentId;
    /**
     * 最后一次委托时间
     */
    @Column(name = "last_experiment_time")
    @ApiModelProperty(value = "最后一次委托时间", name = "lastExperimentTime")
    private Date lastExperimentTime;
    /**
     * 状态  1-正常 0-禁用
     */
    @Column(name = "status")
    @ApiModelProperty(value = "状态  1-正常 0-禁用", name = "status")
    private Integer status;
    /**
     * 创建人
     */
    @Column(name = "creater")
    @ApiModelProperty(value = "创建人", name = "creater")
    private Long creater;
    /**
     * 创建时间
     */
    @Column(name = "create_time")
    @ApiModelProperty(value = "创建时间", name = "createTime")
    private Date createTime;
    /**
     * 修改人
     */
    @Column(name = "updater")
    @ApiModelProperty(value = "修改人", name = "updater")
    private Long updater;
    /**
     * 更新时间
     */
    @Column(name = "update_time")
    @ApiModelProperty(value = "更新时间", name = "updateTime")
    private Date updateTime;
    /**
     * 是否删除  1-删除
     */
    @Column(name = "is_del")
    @ApiModelProperty(value = "是否删除  1-删除", name = "isDel")
    private Integer isDel;

    @Transient
    @ApiModelProperty(value = "物料类型数组  字典 MATERIAL_TYPE", name = "materialsTypeList")
    private List<Integer> materialsTypeList;

    /**
     * 物料名称
     */
    @Transient
    @ApiModelProperty(value = "物料名称", name = "materialsName")
    private String materialsName;
    /**
     * 物料规格
     */
    @Transient
    @ApiModelProperty(value = "物料规格", name = "materialsSpec")
    private String materialsSpec;

    /**
     * 配置的材料类型
     */
    @Transient
    @ApiModelProperty(value = "配置的材料类型", name = "materialsType")
    private Integer materialsConfigType;
    /**
     * 配置的材料名称
     */
    @Transient
    @ApiModelProperty(value = "配置的材料名称", name = "materialsName")
    private String materialsConfigName;
    /**
     * 配置的材料规格
     */
    @Transient
    @ApiModelProperty(value = "配置的材料规格", name = "materialsSpec")
    private String materialsConfigSpec;

    /**
     * 配置的材料简称
     */
    @Transient
    @ApiModelProperty(value = "配置的材料简称")
    private String materialAbbreviation;

    @Transient
    @ApiModelProperty(value = "供应商名称")
    private String supplierCompanyName;

    @Transient
    @ApiModelProperty(value = "供应商名称简称")
    private String supplierAbbreviation;

    @Transient
    @ApiModelProperty(value = "提前预警天数")
    private Integer warningDay;

    @Transient
    @ApiModelProperty(value = "预警状态  0-正常 1-预警 2-过期")
    private Integer warningStatus;

    @Transient
    @ApiModelProperty(value = "erp供货单位唯一标识  ycid")
    @NotNull(groups = {UpdateGroup.class}, message = "erp供货单位唯一标识为空")
    private Long erpCompanyId;

    @Transient
    @ApiModelProperty(value = "erp供货单位物料唯一标识  CYRID")
    @NotNull(groups = {UpdateGroup.class}, message = "erp供货单位物料唯一标识为空")
    private Long erpWlId;

    public SupplierCompanyMaterials init(boolean isCreate) {
        this.setUpdater(StpUtil.isLogin() ? StpUtil.getLoginIdAsLong() : null)
                .setUpdateTime(new Date());
        if (isCreate) {
            this.setCreater(StpUtil.isLogin() ? StpUtil.getLoginIdAsLong() : null)
                    .setCreateTime(new Date())
                    .setStatus(1)
                    .setIsDel(0).setMaterialsNo(UidUtils.genNo(GenerateCodeEnum.SUPPLIER_COMPANY_MATERIALS.getCode()));
        }
        return this;
    }

    public SupplierCompanyMaterials syncInit(boolean isCreate) {
        this.setUpdateTime(new Date());
        if (isCreate) {
            this.setCreateTime(new Date())
                    .setStatus(1)
                    .setIsDel(0).setMaterialsNo(UidUtils.genNo(GenerateCodeEnum.SUPPLIER_COMPANY_MATERIALS.getCode()));
        }
        return this;
    }
}
